package com.max.baselib.widget.toolbar

import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import com.max.baselib.widget.toolbar.ToolbarConstants.Companion.def_titleStyle_NaN
import com.mxin.ui.R

/**
 *  Created by ：2020/7/27
 *  author : Administrator
 *  Toolbar 标题文字居中
 */
class ToolbarHelperCenterTitle(view : View) : ToolbarHelperLeftTitle(view)  {

    override fun setTitle(title: String?, titleStyle: Int) {
        //创建一个TextView到Toolbar中
        var tvTitle : TextView? = titleView.findViewById(R.id.toolbar_title)
        if(tvTitle==null){
            val textView = TextView(titleView.context)
            textView.id = R.id.toolbar_title
            textView.gravity = Gravity.CENTER
            if(titleStyle != def_titleStyle_NaN){
                textView.setTextAppearance(titleView.context, titleStyle)
            }

            tvTitle = textView
            titleView.addView(textView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        }
        tvTitle.text = title
    }

    override fun getDefaultTitleStyle(): Int {
        return R.style.toolbarTitleStyle
    }

}